<template>
		<view class="content">
			<view class="head">
				<image src="../../static/image/login-bg.png" mode=""></image>
			</view>
			<view class="back" @click="toBack">
				<image src="../../static/image/back.png" mode=""></image>
			</view>
			<scroll-view style="width:100%;height:100%;" scroll-y="true" >
				<view style="width:100%;height:720rpx;"></view>
				<view class="login-box">
					<view class="login-content">
						<view class="title">註冊</view>
						<view class="tips" style="opacity: 0;">注册</view>
						<view class="one-infor" style="border-bottom:1px solid #F0F0F0">
							<input type="tel" v-model="tel" placeholder-style="color:#9E9E9E" placeholder="請輸入手機號">
						</view>
						<view class="one-infor" style="border-bottom:1px solid #F0F0F0" >
							<input type="text" v-model="code" placeholder-style="color:#9E9E9E" placeholder="請輸入驗證碼">
							<view class="send-code" v-if="!haveSend" @click="sendCode">發送驗證碼</view>
							<view class="countDown" @click="sendCode" v-if="haveSend">
								重新發送<text v-if="countNum>0">（{{countNum}}s）</text>
							</view>
						</view>
						<view class="one-infor">
							<input type="password" v-model="password" placeholder-style="color:#9E9E9E" placeholder="請輸入密碼">
						</view>
						<view class="login-btn" @click="toRegister">註冊</view>
						<view class="code" @click="toBack">賬號登錄</view>
						<view class="agreement" @click="toAgree">
							<view class="isCheck" v-if="isAgree">
								<image src="../../static/image/check.png" mode=""></image>
							</view>
							<view class="noCheck"  v-if="!isAgree"></view>
							<view class="agree">
								註冊即同意<text @click.stop="showAgreement('user_register_content')">《用戶註冊協議》</text><text @click.stop="showAgreement('user_privacy_content')">《隱私政策》</text>
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
</template>

<script>
	import {register} from '../../request/api.js'
	export default {
		data() {
			return {
				isAgree:false,
				countNum:0,
				haveSend:false,
				tel:'',
				password:'',
				code:""
			};
		},
		methods:{
			showAgreement(e){
				uni.navigateTo({
					url:'/pages/agreement/agreement?type='+e
				})
			},
			// 确定
			async toRegister(){
				if(!this.isAgree){
					uni.showToast({
						title: '請閱讀並同意註冊協議',
						icon: 'none'
					})
					return
				}
				if(!this.tel){
					uni.showToast({
						title: '請填寫註冊手機號',
						icon: 'none'
					})
					return
				}
				if(!this.code){
					uni.showToast({
						title: '請填寫驗證碼',
						icon: 'none'
					})
					return
				}
				if (!/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/.test(this.tel)){
					uni.showToast({
						title: '請填寫正確手機號',
						icon: 'none'
					})
					return
				}
				if(!this.password){
					uni.showToast({
						title: '請填寫密碼',
						icon: 'none'
					})
					return
				}
				uni.showLoading({
					title:'提交中...'
				})
				let res=await register({
					mobile:this.tel,
					code:this.code,
					password:this.password
				})
				uni.hideLoading()
				console.log(res);
				if(res.code==1){
					uni.showToast({
						title: '註冊成功',
						icon: 'none'
					})
					this.tel='';
					this.code='';
					this.password='';
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				}
			},
			toAgree(){
				this.isAgree=!this.isAgree
			},
			toBack(){
				uni.navigateBack()
			},
			// 发送验证码
			sendCode(){
				if(this.countNum>0){
					return;
				}
				this.haveSend=true;
				this.countNum=60;
				let timeInter=setInterval(()=>{
					if(this.countNum>0){
						this.countNum--;
					}else{
						clearInterval(timeInter);
					}
				},1000)
				
			}
		}
	}
</script>

<style lang="scss">
	.content{
		width:100%;height:100vh;
		.head{
			position: absolute;top:0;left:0;
			width:100%;height:720rpx;z-index: -1;
			image{
				width:100%;height:720rpx;
			}
		}
		.back{
			width:55rpx;height:55rpx;
			position: absolute;z-index: 1000;
			top:80rpx;left:30rpx;
			image{
				width:55rpx;height:55rpx;
			}
		}
		.login-box{
			width:100%;background-color:#fff;padding-top:60rpx;
			border-top-left-radius:15rpx;border-top-right-radius: 15rpx;
			padding-bottom:50rpx;
		}
		.login-content{
			width:650rpx;margin-left:auto;
			margin-right:auto;
			.title{
				font-size:40rpx;color:#040404;
				line-height:56rpx;font-weight:bold;
			}
			.tips{
				font-size:24rpx;colro:#040404;
				line-height:33rpx;margin-top:15rpx;
				margin-bottom:30rpx;
				text{
					color:#D71B0A;
				}
			}
			.one-infor{
				padding:40rpx 0rpx;width:100%;
				display: flex;align-items: center;
				justify-content:space-between;
				padding-right:40rpx;
				input{
					font-size:28rpx;color:#333;flex:1;
				}
				.send-code{
					font-size: 28rpx;color:#333333;
				}
				.countDown{
					font-size: 28rpx;color:#D71B0A;
				}
			}
		}
		.login-btn{
			width:100%;height:98rpx;display: flex;align-items: center;
			justify-content: center;background-color:#040404;color:#fff;
			font-size:36rpx;font-weight: 500;border-radius: 98rpx;
			margin-top:80rpx;
		}
		.code{
			font-size: 28rpx;color:#9E9E9E;margin-top:30rpx;
			line-height:40rpx;text-align: center;
		}
		.agreement{
			margin-top:109rpx;display: flex;align-items: center;
			justify-content: center;
			.isCheck{
				width:26rpx;height:26rpx;
				image{
					width:26rpx;height:26rpx;display: block;
				}
			}
			.noCheck{
				width:26rpx;height:26rpx;box-sizing: border-box;
				border:1px solid #9E9E9E;border-radius: 50%;
			}
			.agree{
				font-size: 24rpx;color:#9E9E9E;margin-left:10rpx;
				text{
					color:#040404
				}
			}
		}
	}
</style>
